home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / BAR3D.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  1.2 KB  |  48 lines

  1.                                             /* bar3d.c */
  2.                                  /* Entered by A. Wayner */
  3.  
  4. # include <graphics.h>
  5. # include <stdlib.h>
  6.  
  7. main()
  8. {
  9.     int graphdriver = DETECT;
  10.     int graphmode, i;
  11.     int data[5] = {2, 1, 3, 5, 4 }, maxdata = 5, numpt = 5;
  12.     int maxheight, maxwidth, xstep, ystep, x, y, depth, maxcolor;
  13.  
  14.  
  15.                                             /* Detect adapter type and    */
  16.                                             /* initialize graphics system */
  17.       initgraph( &graphdriver, &graphmode, "\\turboc");
  18.     outtextxy( 10, 10, "Bar graphs using 'bar3d' ");
  19.  
  20.                                             /* Now draw the bar graph */
  21.     maxheight = getmaxy() - 100;
  22.     ystep = maxheight / maxdata;
  23.  
  24.     maxwidth = getmaxx() - 200;
  25.     xstep = maxwidth / numpt;
  26.  
  27.     depth = xstep / 4;
  28.  
  29.     x = 100;
  30.     y = maxheight + 40;
  31.  
  32.                                             /* Use random color */
  33.     randomize();
  34.     maxcolor = getmaxcolor();
  35.     for( i = 0; i < numpt; i++, x += xstep )
  36.     {
  37.         setfillstyle( (i % 11) + 1, random( maxcolor ) );
  38.         bar3d( x, y - data[i] * ystep, x + xstep, y, depth, 1 );
  39.     }
  40.                                             /* Wait until user presses a key */
  41.     outtextxy( 10, getmaxy() - 30," Press any key to exit");
  42.  
  43.  
  44.     getch();                                /* Wait until a key is pressed */
  45.     closegraph();                        /* Exit graphics library */
  46.  
  47. }
  48.